package com.czr.admin.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

//WebMvcConfigurer 自定义mvc配置（扩展mvc）
@Configuration
public class MyConfig implements WebMvcConfigurer {

    // 视图跳转
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("/login");
        registry.addViewController("/index.html").setViewName("/index");
        //registry.addViewController("/index").setViewName("/index");
        registry.addViewController("/login").setViewName("/login");
        registry.addViewController("/login.html").setViewName("/login");

        // 去添加页面
        registry.addViewController("/toAddMember").setViewName("/admin/memberAdd");

    }

    // 添加拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginHandlerInterceptor())
                .addPathPatterns("/**")  // 拦截哪些请求
                .excludePathPatterns("/", "/admin/**", "/admin/images/**", "/login", "/index", "/css/**", "/js/**", "/images/**", "/lib/**", "/img/**", "/favicon.ico"); // 放行哪些请求
    }




}
